from Netease_playlist_info import *
from Netease_song_info_not_img import *
import time

def all_run():
    playlist_id = input('网易云歌单id：')  # 6638111891  4900784000
    playlist_info = playlist(playlist_id)
    title, song_id_list, song_name_list = playlist_info.run()

    now_time = time.strftime('%Y%m%d_%H时%M分%S秒', time.localtime())
    path = './' + now_time + ' '+title + '.txt'
    with open(path, 'a+', encoding='utf8') as fp:
        fp.write(f'''{title}
歌单链接：https://music.163.com/#/playlist?id={playlist_id}

''')

    fail_list = []
    num_initial = 0

    for i in range(len(song_id_list)):
        num = i + num_initial
        song_info = song_info_not_img()
        try:
            song_data = f'''{num + 1}.《{song_info.run(song_id_list[num])}》
https://music.163.com/#/song?id={song_id_list[num]}

'''
        except:
            song_data = f'''{num + 1}.《{song_name_list[num]}》_____________________________________________获取失败
https://music.163.com/#/song?id={song_id_list[num]}

'''
            print(f'{num + 1}.《{song_name_list[num]}》_____________________________________________获取失败')
            fail_list.append({num+1}) #添加进失败列表
        finally:
            with open(path, 'a+', encoding='utf8') as fp:
                fp.write(song_data)
    if fail_list != []:
        with open(path, 'a+', encoding='utf8') as fp:
            fp.write(f'{fail_list} + 获取失败')

if __name__ == '__main__':
    all_run()
    print('playlist over!')
